import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/pages/index/Index'
import MyParticipation from '@/pages/my_participation/MyParticipationList'
import Detail from '@/pages/detail/Detail'
import Description from '@/pages/description/Description'
import Ranking from '@/pages/ranking/RankingList'
import Hybrid from '@/pages/hybrid/Index'
import H5Register from '@/pages/hybrid/H5Register'
import H5Notify from '@/pages/hybrid/H5Notify'
import LifecircleA from '@/pages/hybrid/LifecircleA'
import LifecircleB from '@/pages/hybrid/LifecircleB'
import H5Scan from '@/pages/hybrid/H5Scan'

Vue.use(Router)
const PROJECT_NAME = '/wcc_funding'
export default new Router({
  mode: 'history',
  routes: [
    {
      path: buildRouter(''),
      name: 'Index',
      component: Index
    },
    {
      path: buildRouter('index'),
      name: 'Index',
      component: Index
    },
    {
      path: buildRouter('myparticipation'),
      name: 'MyParticipation',
      component: MyParticipation
    },
    {
      path: buildRouter('detail'),
      name: 'Detail',
      component: Detail
    },
    {
      path: buildRouter('description'),
      name: 'Description',
      component: Description
    },
    {
      path: buildRouter('hybrid'),
      name: 'Hybrid',
      component: Hybrid
    },
    {
      path: buildRouter('h5register'),
      name: 'H5Register',
      component: H5Register
    },
    {
      path: buildRouter('h5notify'),
      name: 'H5Notify',
      component: H5Notify
    },
    {
      path: buildRouter('lifecirclea'),
      name: 'LifecircleA',
      component: LifecircleA
    },
    {
      path: buildRouter('lifecircleb'),
      name: 'LifecircleB',
      component: LifecircleB
    },
    {
      path: buildRouter('h5scan'),
      name: 'H5Scan',
      component: H5Scan
    }

  ]
})

/**
 * 用于构建路由
 * 浏览器的访问路径为：http://localhost:8080/项目名/path
 * @param path 需要导航的地址 eg: index
 * @returns {string} 真正的路由 eg: /wcc/index
 */
function buildRouter(path) {
  // 如果是正式环境，路由需要增加项目名
  if (process.env.NODE_ENV === 'production') {
    return PROJECT_NAME + "/" + path;
  } else {
    return "/" + path;
  }
}
